package org.qdog.pk.pkscrape.entity;

import org.apache.log4j.Logger;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;

/**
 * @since 08/2011
 */
@javax.persistence.Entity
@Table(name = "entities")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, length = 20)
public abstract class Entity implements PersistentObject {
  private static final Logger log = Logger.getLogger(Entity.class);

  @Id
  @Column(name = "id", length = 40)
  private String id;

  @Temporal(TemporalType.DATE)
  @Column(name = "start_date", nullable = true)
  private Date start;

  @Temporal(TemporalType.DATE)
  @Column(name = "end_date", nullable = true)
  private Date end;

  @Column(name = "name", length = 100, nullable = true)
  private String name;

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "last_update", nullable = true)
  private Date lastUpdate;

  @Column(name = "member_count", nullable = true)
  private Integer memberCount;

  @Column(name = "active_member_count", nullable = true)
  private Integer activeMemberCount;

  public Entity() {

  }

  public Entity(String id) {
    this.id = id;

  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public Date getStart() {
    return start;
  }

  public void setStart(Date start) {
    this.start = start;
  }

  public Date getEnd() {
    return end;
  }

  public void setEnd(Date end) {
    this.end = end;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Date getLastUpdate() {
    return lastUpdate;
  }

  public void setLastUpdate(Date lastUpdate) {
    this.lastUpdate = lastUpdate;
  }

  public Integer getMemberCount() {
    return memberCount;
  }

  public void setMemberCount(Integer memberCount) {
    this.memberCount = memberCount;
  }

  public Integer getActiveMemberCount() {
    return activeMemberCount;
  }

  public void setActiveMemberCount(Integer activeMemberCount) {
    this.activeMemberCount = activeMemberCount;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof Entity)) return false;

    Entity entity = (Entity) o;

    if (!id.equals(entity.id)) return false;

    return true;
  }

  @Override
  public int hashCode() {
    return id.hashCode();
  }
}
